home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / OpenURL / Rexx / SendThorMail.rexx < prev   
OS/2 REXX Batch file  |  1999-09-15  |  4KB  |  120 lines

  1. /*
  2. $VER: SendThorMail.rexx 2.1 (15.9.99) Neil Bothwick
  3. A Thor script to create a Thor email event
  4. This is a modified version for use with OpenURL
  5. */
  6.  
  7. /* ;;; Initialise */
  8. options results
  9. if ~show('p', 'BBSREAD') then do
  10.     address command
  11.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  12.     'WaitForPort BBSREAD'
  13.     end
  14. CDF_MAIL = '00000002'x  /* Private mail conference. */
  15. CDB_MAIL = 1  /* Private mail conference. */
  16. ;;;
  17. /* ;;; Read arguments */
  18. parse arg arguments
  19. template = 'SYSTEM/K,CONF/K,ADDRESS/A/K,NAME/K,SUBJECT/K,TEXT/K,CC/K,BCC/K,ATTACH/K'
  20. drop ARGS.
  21. ARGS.SUBJECT= ' '
  22. ARGS.TEXT = 'STDIN'
  23. address(BBSREAD)
  24. READARGS template ARGS CMDLINE arguments
  25. if RC = 5 then call ExitMsg('Usage: SendThorMail.rexx' template)
  26. ;;;
  27. /* ;;; Get System and Conference if not given on command line */
  28. if symbol('ARGS.SYSTEM') ~= 'VAR' then do
  29.     drop Systems.
  30.     'GETBBSLIST stem SYSTEMS'
  31.  
  32.     do i = 1 to Systems.COUNT
  33.         SystemName = Systems.i
  34.         drop SysData.
  35.         'GETBBSDATA bbsname "'Systems.i'" stem SYSDATA'
  36.         if left(SysData.BBSTYPE,3) = 'TCP' then do
  37.             ARGS.SYSTEM = Systems.i
  38.             leave
  39.             end
  40.         end
  41.     end
  42.  
  43. call CheckSystem()
  44. if symbol('ARGS.CONF') ~= 'VAR' then ARGS.CONF = 'Email'
  45. ;;;
  46.  
  47. /* ;;; Create message file */
  48. address(BBSREAD)
  49. drop SysInfo.
  50. GETBBSDATA bbsname '"'ARGS.SYSTEM'"' stem SysInfo
  51.  
  52. UNIQUEMSGFILE bbsname '"'ARGS.SYSTEM'"' stem MsgFile
  53. if ~open(out,MsgFile.NAME,'w') then call ExitMsg('Unable to create message file')
  54. if symbol('ARGS.CC') = VAR then call writeln(out,'cc:' ARGS.CC)
  55. if symbol('ARGS.BCC') = VAR then call writeln(out,'bcc:' ARGS.BCC)
  56.  
  57. /* Add contents of .header */
  58. if exists(SysInfo.BBSPATH||'.header') then do
  59.     if ~open(hdr,SysInfo.BBSPATH||'.header','r') then call ExitMsg('Could not open header file')
  60.     do until eof(hdr)
  61.         call writeln(out,readln(hdr))
  62.         end
  63.     call close(hdr)
  64.     end
  65. else if symbol('ARGS.CC') = VAR | symbol('ARGS.BCC') = VAR then call writeln(out,'')
  66.  
  67. /* Copy from text to message file */
  68. if ARGS.TEXT = 'STDIN' then do
  69.     do until eof('STDIN')
  70.         call writeln(out,compress(readln('STDIN'),'0d'x))       /* Strip superfluous CRs */
  71.         end
  72.     end
  73. else do
  74.     if ~open(text,ARGS.TEXT,'R') then call ExitMsg('Could not read message text file')
  75.     do until eof(text)
  76.         call writeln(out,compress(readln(text),'0d'x))          /* Strip superfluous CRs */
  77.         end
  78.     call close(text)
  79.     end
  80. call close(out)
  81. ;;;
  82. /* ;;; Create email event */
  83. drop EventData.
  84. EventData.TOADDR = ARGS.ADDRESS
  85. EventData.SUBJECT = ARGS.SUBJECT
  86. EventData.CONFERENCE = ARGS.CONF
  87. EventData.MSGFILE = MsgFile.FILEPART
  88. if symbol('ARGS.NAME') = VAR then EventData.TONAME = ARGS.NAME
  89. if symbol('ARGS.ATTACH') = VAR then EventData.LOCALFILE = ARGS.ATTACH
  90.  
  91. WRITEBREVENT bbsname '"'ARGS.SYSTEM'"' event 0 stem EventData
  92. if(rc ~= 0) then call ExitMsg(BBSREAD.LASTERROR)
  93. ;;;
  94.  
  95. exit
  96.  
  97. /* ;;; Exit with a message */
  98. ExitMsg:
  99.     parse arg msg
  100.     if msg > '' then do
  101.         address command 'RequestChoice >NIL: "SendThorMail.rexx" "'msg'" "OK"'
  102.         /*say;say msg;say*/
  103.         exit 5
  104.     else exit
  105.     return
  106. ;;;
  107. /* ;;; Check that the system and conference are valid */
  108. CheckSystem:
  109.     drop SysData.
  110.     'GETBBSDATA bbsname "'ARGS.SYSTEM'" stem SYSDATA'
  111.     if RC > 0 then call ExitMsg('You must specify the name of an Internet system')
  112.     if left(SysData.BBSTYPE,3) ~= 'TCP' then call ExitMsg('You must specify the name of an Internet system')
  113.  
  114.     drop ConfData.
  115.     'GETCONFDATA bbsname "'ARGS.SYSTEM'" confname "'ARGS.CONF'" stem CONFDATA'
  116.     if bittst(ConfData.FLAGS,CDB_MAIL) = 0 then call ExitMsg('You must specify the name of an Email conference')
  117.     return
  118. ;;;
  119.  
  120.